package com.cincc.taofangwang.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cincc.taofangwang.R;
import com.cincc.taofangwang.common.callback.OnClickCallBack;
import com.cincc.taofangwang.model.TaskNumberModel;

import java.util.List;

public class TaskNumberAdapter extends RecyclerView.Adapter<TaskNumberAdapter.MyViewHolder> {
    private Context context;
    private List<TaskNumberModel> list;

    public TaskNumberAdapter(Context context, List<TaskNumberModel> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_number, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        TaskNumberModel model = list.get(position);
        holder.nameText.setText(!TextUtils.isEmpty(model.batchName) ? model.batchName : "");
        holder.numberText.setText(model.taskNumber);
        String content = getStatus(model.taskStatus);
        holder.statusText.setText(content);
        holder.itemView.setOnClickListener(v -> onClickBallBack.callback(position));
    }

    private String getStatus(String status) {
        switch (status) {
            case "2":
                return "未呼叫";
            case "3":
                return "pc已呼";
            case "4":
                return "pc已呼填单";
            case "5":
                return "sj已点击";
            default:
                return "";
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView nameText;
        TextView numberText;
        TextView statusText;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            nameText = itemView.findViewById(R.id.name_tv);
            numberText = itemView.findViewById(R.id.number_tv);
            statusText = itemView.findViewById(R.id.status_tv);
        }
    }

    private OnClickCallBack onClickBallBack;

    public void setCallBack(OnClickCallBack callBack) {
        this.onClickBallBack = callBack;
    }
}
